<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="建设项目" prop="projectId">
        <el-select
          v-model="queryParams.projectId"
          placeholder="建设项目"
          size="small"
          style="width: 240px"
          @change="handleChange"
        >
          <el-option
            v-for="item in projectOptions"
            :key="item.projectId"
            :value="item.projectId"
            :label="item.projectName"></el-option>
        </el-select>
      </el-form-item>

    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click=""-->
<!--          v-hasPermi="['screen:screen:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click=""-->
<!--          v-hasPermi="['screen:screen:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click=""-->
<!--          v-hasPermi="['screen:screen:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="name">
        <template slot-scope="scope">
          <el-link type="primary" @click="openPage(scope.row)">{{ scope.row.name }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { selectProjectList } from "@/api/project/project";
  import { list } from "@/api/screen/screen";

  export default {
    name: "Screen",
    dicts: ['sys_normal_disable'],
    data() {
      return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        list: [],
        // 项目ID
        projectId: 0,
        // 项目列表
        projectOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          projectId: undefined
        },
      }
    },
    created() {
      this.loadProjectList();
    },
    methods: {
      // 加载项目下拉框
      loadProjectList() {
        selectProjectList().then(response => {
          if (response.projects.length > 0) {
            this.projectOptions = response.projects;
            this.queryParams.projectId = response.projects[0].projectId;
            this.getList();
          }
        });
      },
      // 项目下拉框发生变化
      handleChange() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 查询工期列表 */
      getList() {
        this.loading = true;
        list(this.queryParams).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 打开可视化大屏 */
      openPage(row) {
        console.log(this.queryParams.projectId);
        console.log(row.component);
        let routeData = this.$router.resolve({ path: row.component , query: {projectId: this.queryParams.projectId, name: row.name}});
        window.open(routeData.href, '_blank');
      }
    }
  }
</script>
